package com.dx.financehy.modules.schedule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dx.financehy.modules.schedule.domain.Schedule;
import com.dx.financehy.modules.schedule.domain.dto.AddEditScheduleDTO;
import com.dx.financehy.modules.schedule.domain.dto.GetScheduleDTO;
import com.dx.financehy.modules.schedule.domain.vo.ScheduleVO;
import com.dx.financehy.modules.schedule.mapper.ScheduleMapper;
import com.dx.financehy.modules.schedule.service.ScheduleService;
import com.dx.financehy.modules.system.domain.dto.BaseDTO;
import com.dx.financehy.utils.BeanCopyUtil;
import com.dx.financehy.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: huang_jigao
 * @Title: TouristMessagesImpl
 * @ProjectName: financehy
 * @Description:
 * @date: 2024-05-16 10:56
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements ScheduleService {

    /**
     * 待办事项
     *
     * @param req
     * @return
     */
    @Override
    public List<ScheduleVO> getList(GetScheduleDTO req){
        return baseMapper.getList(req);
    }

    /**
     * 获取待办事项详情
     *
     * @param req
     * @return
     */
    @Override
    public ScheduleVO getScheduleDetail(BaseDTO req){
        LambdaQueryWrapper<Schedule> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Schedule::getId,req.getId());
        Schedule schedule = baseMapper.selectOne(queryWrapper);
        ScheduleVO vo = BeanCopyUtil.copy(schedule,ScheduleVO.class);
        return vo;
    }

    /**
     * 新增编辑待办事项
     *
     * @param dto
     */
    @Override
    public void addSchedule(AddEditScheduleDTO dto){
        Schedule schedule = BeanCopyUtil.copy(dto,Schedule.class);
        if (StringUtils.isBlank(dto.getId())){
            baseMapper.insert(schedule);
        }else {
            baseMapper.updateById(schedule);
        }
    }

    /**
     * 删除待办事项
     *
     * @param req
     */
    @Override
    public void delSchedule(BaseDTO req){
        LambdaUpdateWrapper<Schedule> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Schedule::getId,req.getId());
        updateWrapper.set(Schedule::getDeleted,true);
        baseMapper.update(null,updateWrapper);
    }
}
